package com.zz.client.config;

import com.zz.common.config.Config;
import com.zz.common.config.Constants;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * 客户端配置类
 */
@Slf4j
@Getter
public class TunnelClientConfig implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 代理服务器绑定主机host
     */
    private String serverBind;

    /**
     * 代理服务器与代理客户端通信端口
     */
    private Integer serverPort;

    private String clientId;

    private String clientKey;


    @Getter
    private static TunnelClientConfig instance = new TunnelClientConfig();

    private TunnelClientConfig() {
        // 代理服务器主机和端口配置初始化
        this.serverPort = Config.getInstance().getIntValue("server.port");
        this.serverBind = Config.getInstance().getStringValue("server.bind", "0.0.0.0");

        log.info("config init serverBind {}, serverPort {}", serverBind, serverPort);
        setClientInfo();
    }

    private void setClientInfo() {
        // 当数据源为内存数据源时默认使用配置文件中的clientId和clientKey
        if (Config.getInstance().getDataSourceType().equals(Constants.Strings.DEFAULT_SOURCE)) {
            this.clientId = Config.getInstance().getStringValue("connect.client.id");
            this.clientKey = Config.getInstance().getStringValue("connect.client.key");
        }
    }

}
